import GA_Test.*;

import java.util.ArrayList;

/**
 * 本算法为初始解算法
 * 初始解算法 是随机生成 100 个种群  从100 个种群中 挑选出 最好的个体
 */
public class Test02 {
    static int[] truck_cap = new int[]{112,200,200,200,200,200,200,65,200,1200,900,1800,2000,2100,2300,2500};
    static int[] drone_cap = new int[]{40,40,40,40,40,40,40,20,40,40,40,40,40,40,40,40};
    public static void main(String[] args) {
        ArrayList<Object> all = new ArrayList<>();
        for(int l = 10;l<16;l++){
            Object[] obj = ReadData.ReadNode();
            GAData.capacityTruck = truck_cap[l];
            GAData.capacityDrone = drone_cap[l];
            GAData.disCollection = (Double[][]) obj[1];
            GAData.cusInfo = (Node[]) obj[0];
            ArrayList<Object> route_result = new ArrayList<>();
            long startTime = System.currentTimeMillis();
            for(int k =0;k<5;k++) {
                double avg = 0;
                double best = 9999.0;


                for (int i = 0; i < 1000; i++) {
                    GeneticAlgorithm GA = new GeneticAlgorithm();
                    SpeciesPopulation speciesPopulation = new SpeciesPopulation();
                    GA.createBeginningSpecies(speciesPopulation);
                    double global_opt_solution = GA.calRate(speciesPopulation);
                    if (global_opt_solution < best) {
                        best = global_opt_solution;
                    }
                    //System.out.println(global_opt_solution);
                    avg += global_opt_solution;
                }
                //System.out.println("最优值为" + best);
                //System.out.println("平均值为"  + avg/1000);

                //System.out.println("程序运行时间" + (endTime-startTime));
                route_result.add(best);
            }
            long endTime = System.currentTimeMillis();
            route_result.add((endTime-startTime)/5);
            all.add(route_result);
            for(int o = 0;o<all.size();o++){  //打印所有算例运行结果
                System.out.println(all.get(o));
            }
        }


    }
}
